//


#import "NT_SetViewController.h"
#import "NT_AboutViewController.h"
#import "NT_FeedBackViewController.h"

@interface NT_SetViewController ()<UITableViewDelegate,UITableViewDataSource>
/** */
@property (nonatomic, strong) UITableView *setTableView;
/** */
@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation NT_SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self setnavBatTitle:@"Set"];
    _dataArray = @[@"Call Us",@"Clear Hirstoy",@"Version",@"About",@"Feedback"];
    
    [self.view addSubview:self.setTableView];
}

//#pragma mark ----------------- tableViewDelegate ----------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = _dataArray[indexPath.row];
    if (indexPath.row == 0) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.detailTextLabel.text = @"call";
    }else if (indexPath.row == 1){
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.detailTextLabel.text = @"clear";
    }else if (indexPath.row == 2){
        cell.detailTextLabel.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    }else{
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kRelativeHeight(10);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //
    if (indexPath.row == 0) {
        //
        NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"0571-88263930"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        
    }else if (indexPath.row == 1){
        NT_CoreDataBase *data = [[NT_CoreDataBase alloc]initWithCoreData:@"DeleData" modelName:@"NoteData" success:^{} fail:^(NSError * _Nullable error) {}];
        //
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:@"Are you sure you want to clear it?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * sureAction = [UIAlertAction  actionWithTitle:@"ok"style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnullaction){
            //
            [data ntDeleteEntity:nil key:[NSString stringWithFormat:@"id = 2"] success:^{} fail:^(NSError * _Nullable error) {}];
        }];
        UIAlertAction * cancelAction = [UIAlertAction  actionWithTitle:@"cancel"style:UIAlertActionStyleCancel handler:^(UIAlertAction*_Nonnullaction){
        }];
        [alertC addAction:sureAction];
        [alertC addAction:cancelAction];
        [self presentViewController:alertC animated:YES completion:nil];
        
    }else if (indexPath.row == 3){
        NT_AboutViewController *vc = [[NT_AboutViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 4){
        NT_FeedBackViewController *vc = [[NT_FeedBackViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

//
#pragma mark ----------------- 懒加载 ----------------
- (UITableView *)setTableView {
    if (!_setTableView) {
        _setTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, UI_NAV_BAR_HEIGHT, kMainScreenWidth, kMainScreenHeight) style:UITableViewStylePlain];
        _setTableView.dataSource = self;
        _setTableView.delegate   = self;
        _setTableView.tableFooterView = [UIView new];
        _setTableView.rowHeight  = kRelativeHeight(50);
    }
    return _setTableView;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
- (BOOL)nt_isShowLeft {
    return NO;
}

@end
